package com.example.batch.reader;

import org.springframework.batch.item.file.MultiResourceItemReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.PathResource;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2021/7/17 17:34
 * @Description TODO
 */
@Configuration
public class MyMultiResourceFlatFileItemReader<String> extends MultiResourceItemReader {

    private java.lang.String package_path = "/Users/yuhang/Downloads/";

    @Autowired
    private MyFlatFileReader reader;


    public MyMultiResourceFlatFileItemReader() {
        java.lang.String[] resource = {"result.txt","temp.txt"};

        PathResource[] pathResources = Arrays
                .stream(resource)
                .map(v -> package_path + v)
                .map(PathResource::new)
                .collect(Collectors.toList())
                .toArray(new PathResource[]{});

        setResources(pathResources);

    }


    @PostConstruct
    public void init() {
        setDelegate(reader);
    }
}
